package com.tisson.action;

import java.util.ArrayList;
import java.util.List;

import com.tisson.action.ActionSup;
import com.tisson.bo.BuildingBO;
import com.tisson.bo.DistrictBO;
import com.tisson.bo.PurviewBO;
import com.tisson.comment.WebConstants;
import com.tisson.pojo.Page;


public class SearchAction extends ActionSup{
	
	private Page page;
	private String areaId;
	private String areaName;
	private String areaLocation;
	private String areaComment;
	private String districtId;
	private String districtName;
	private String districtLocation;
	private String districtComment;
	private String buildingId;
	private String buildingName;
	private String buildingLocation;
	private String buildingComment;
	private String doorId;
	private String doorSerial;
	private String doorName;
	private String doorAddress;
	private Integer doorSystem;
	private Integer doorTic;
	private Integer doorChn;
	private List result;
	private List areaList;
	private List districtList;
	private List buildingList;
	private List doorList;
	private String aid;
	private String did;
	private String bid;
	
	public String searchList(){
		PurviewBO bo =  new PurviewBO();
		page = new Page();
		List all;
		result = new ArrayList();
		districtList = new ArrayList();
		buildingList = new ArrayList();
		doorList = new ArrayList();
		areaList = bo.getOptionArea(request);
		if(areaList.isEmpty()){
			return "areaList";
		}else{
			districtList = bo.getOptionDistrict(areaId);
			String dId = getDistrictId();
			if(dId == null){
				
			}
			if(districtList.isEmpty()){
				try{
					all = bo.getOptionArea(request);
				}
				catch(Exception e){
					e.printStackTrace();
					all = new ArrayList();
				}
				request.getSession().setAttribute("list", all);
				try{
					for(int i=0;i<WebConstants.PAGESIZE;i++){
						if(all.get(i)!=null){
							result.add(all.get(i));
						}
					}
				}catch(Exception e){
				}
				page.setCurrentPage(1);
				page.setPrePage(page.getCurrentPage()-1);
				page.setNextPage(page.getCurrentPage()+1);
				page.setListSize(all.size());
				page.setTotalPages(page.getListSize()%WebConstants.PAGESIZE==0?page.getListSize()/WebConstants.PAGESIZE:(page.getListSize()/WebConstants.PAGESIZE)+1);
				return "areaList";
			}else{
				buildingList = bo.getOptionBuilding(districtId);
				if(buildingList.isEmpty()){
					try{
						all = bo.getOptionDistrict(areaId);
					}
					catch(Exception e){
						e.printStackTrace();
						all = new ArrayList();
					}
					request.getSession().setAttribute("list", all);
					try{
						for(int i=0;i<WebConstants.PAGESIZE;i++){
							if(all.get(i)!=null){
								result.add(all.get(i));
							}
						}
					}catch(Exception e){
					}
					page.setCurrentPage(1);
					page.setPrePage(page.getCurrentPage()-1);
					page.setNextPage(page.getCurrentPage()+1);
					page.setListSize(all.size());
					page.setTotalPages(page.getListSize()%WebConstants.PAGESIZE==0?page.getListSize()/WebConstants.PAGESIZE:(page.getListSize()/WebConstants.PAGESIZE)+1);
					return "districtList";
				}else{
					doorList = bo.getOptionDoor(buildingId);
					if(doorList.isEmpty()){
						try{
							all = bo.getOptionBuilding(districtId);
						}
						catch(Exception e){
							e.printStackTrace();
							all = new ArrayList();
						}
						request.getSession().setAttribute("list", all);
						try{
							for(int i=0;i<WebConstants.PAGESIZE;i++){
								if(all.get(i)!=null){
									result.add(all.get(i));
								}
							}
						}catch(Exception e){
						}
						page.setCurrentPage(1);
						page.setPrePage(page.getCurrentPage()-1);
						page.setNextPage(page.getCurrentPage()+1);
						page.setListSize(all.size());
						page.setTotalPages(page.getListSize()%WebConstants.PAGESIZE==0?page.getListSize()/WebConstants.PAGESIZE:(page.getListSize()/WebConstants.PAGESIZE)+1);
						return "buildingList";
					}else{
						try{
							all = bo.getOptionDoor(buildingId);
						}
						catch(Exception e){
							e.printStackTrace();
							all = new ArrayList();
						}
						request.getSession().setAttribute("list", all);
						try{
							for(int i=0;i<WebConstants.PAGESIZE;i++){
								if(all.get(i)!=null){
									result.add(all.get(i));
								}
							}
						}catch(Exception e){
						}
						page.setCurrentPage(1);
						page.setPrePage(page.getCurrentPage()-1);
						page.setNextPage(page.getCurrentPage()+1);
						page.setListSize(all.size());
						page.setTotalPages(page.getListSize()%WebConstants.PAGESIZE==0?page.getListSize()/WebConstants.PAGESIZE:(page.getListSize()/WebConstants.PAGESIZE)+1);
						return "doorList";
					}
				}
			}
		}
	}
	
	public String districtList(){
		PurviewBO bo =  new PurviewBO();
		page = new Page();
		List all;
		setAreaId(aid);
		result = new ArrayList();
		areaList = bo.getOptionArea(request);
		districtList = bo.getOptionDistrict(aid);
		buildingList = bo.getOptionBuilding(did);
		doorList = new ArrayList();
		try{
			all = bo.getOptionDistrict(aid);
		}
		catch(Exception e){
			e.printStackTrace();
			all = new ArrayList();
		}
		request.getSession().setAttribute("list", all);
		try{
			for(int i=0;i<WebConstants.PAGESIZE;i++){
				if(all.get(i)!=null){
					result.add(all.get(i));
				}
			}
		}catch(Exception e){
		}
		page.setCurrentPage(1);
		page.setPrePage(page.getCurrentPage()-1);
		page.setNextPage(page.getCurrentPage()+1);
		page.setListSize(all.size());
		page.setTotalPages(page.getListSize()%WebConstants.PAGESIZE==0?page.getListSize()/WebConstants.PAGESIZE:(page.getListSize()/WebConstants.PAGESIZE)+1);
		return "districtList";
	}

	public String buildingList(){
		PurviewBO bo =  new PurviewBO();
		page = new Page();
		List all;
		setAreaId(aid);
		setDistrictId(did);
		result = new ArrayList();
		areaList = bo.getOptionArea(request);
		districtList = bo.getOptionDistrict(aid);
		buildingList = bo.getOptionBuilding(did);
		doorList = bo.getOptionDoor(buildingId);
		try{
			all = bo.getOptionBuilding(did);
		}
		catch(Exception e){
			e.printStackTrace();
			all = new ArrayList();
		}
		request.getSession().setAttribute("list", all);
		try{
			for(int i=0;i<WebConstants.PAGESIZE;i++){
				if(all.get(i)!=null){
					result.add(all.get(i));
				}
			}
		}catch(Exception e){
		}
		page.setCurrentPage(1);
		page.setPrePage(page.getCurrentPage()-1);
		page.setNextPage(page.getCurrentPage()+1);
		page.setListSize(all.size());
		page.setTotalPages(page.getListSize()%WebConstants.PAGESIZE==0?page.getListSize()/WebConstants.PAGESIZE:(page.getListSize()/WebConstants.PAGESIZE)+1);
		return "buildingList";
	}
	
	public String doorList(){
		PurviewBO bo =  new PurviewBO();
		page = new Page();
		List all;
		setAreaId(aid);
		setDistrictId(did);
		setBuildingId(bid);
		result = new ArrayList();
		areaList = bo.getOptionArea(request);
		districtList = bo.getOptionDistrict(aid);
		buildingList = bo.getOptionBuilding(did);
		doorList = bo.getOptionDoor(bid);
		try{
			all = bo.getOptionDoor(bid);
		}
		catch(Exception e){
			e.printStackTrace();
			all = new ArrayList();
		}
		request.getSession().setAttribute("list", all);
		try{
			for(int i=0;i<WebConstants.PAGESIZE;i++){
				if(all.get(i)!=null){
					result.add(all.get(i));
				}
			}
		}catch(Exception e){
		}
		page.setCurrentPage(1);
		page.setPrePage(page.getCurrentPage()-1);
		page.setNextPage(page.getCurrentPage()+1);
		page.setListSize(all.size());
		page.setTotalPages(page.getListSize()%WebConstants.PAGESIZE==0?page.getListSize()/WebConstants.PAGESIZE:(page.getListSize()/WebConstants.PAGESIZE)+1);
		return "doorList";
	}
	
	public Page getPage() {
		return page;
	}

	public void setPage(Page page) {
		this.page = page;
	}

	public String getDoorId() {
		return doorId;
	}

	public void setDoorId(String doorId) {
		this.doorId = doorId;
	}

	public String getAreaId() {
		return areaId;
	}

	public void setAreaId(String areaId) {
		this.areaId = areaId;
	}

	public String getDistrictId() {
		return districtId;
	}

	public void setDistrictId(String districtId) {
		this.districtId = districtId;
	}

	public String getBuildingId() {
		return buildingId;
	}

	public void setBuildingId(String buildingId) {
		this.buildingId = buildingId;
	}

	public List getResult() {
		return result;
	}

	public void setResult(List result) {
		this.result = result;
	}

	public List getAreaList() {
		return areaList;
	}

	public void setAreaList(List areaList) {
		this.areaList = areaList;
	}

	public List getDistrictList() {
		return districtList;
	}

	public void setDistrictList(List districtList) {
		this.districtList = districtList;
	}

	public List getBuildingList() {
		return buildingList;
	}

	public void setBuildingList(List buildingList) {
		this.buildingList = buildingList;
	}

	public List getDoorList() {
		return doorList;
	}

	public void setDoorList(List doorList) {
		this.doorList = doorList;
	}

	public String getAreaName() {
		return areaName;
	}

	public void setAreaName(String areaName) {
		this.areaName = areaName;
	}

	public String getAreaLocation() {
		return areaLocation;
	}

	public void setAreaLocation(String areaLocation) {
		this.areaLocation = areaLocation;
	}

	public String getAreaComment() {
		return areaComment;
	}

	public void setAreaComment(String areaComment) {
		this.areaComment = areaComment;
	}

	public String getDistrictName() {
		return districtName;
	}

	public void setDistrictName(String districtName) {
		this.districtName = districtName;
	}

	public String getDistrictLocation() {
		return districtLocation;
	}

	public void setDistrictLocation(String districtLocation) {
		this.districtLocation = districtLocation;
	}

	public String getDistrictComment() {
		return districtComment;
	}

	public void setDistrictComment(String districtComment) {
		this.districtComment = districtComment;
	}

	public String getBuildingName() {
		return buildingName;
	}

	public void setBuildingName(String buildingName) {
		this.buildingName = buildingName;
	}

	public String getBuildingLocation() {
		return buildingLocation;
	}

	public void setBuildingLocation(String buildingLocation) {
		this.buildingLocation = buildingLocation;
	}

	public String getBuildingComment() {
		return buildingComment;
	}

	public void setBuildingComment(String buildingComment) {
		this.buildingComment = buildingComment;
	}

	public String getAid() {
		return aid;
	}

	public void setAid(String aid) {
		this.aid = aid;
	}

	public String getDid() {
		return did;
	}

	public void setDid(String did) {
		this.did = did;
	}

	public String getBid() {
		return bid;
	}

	public void setBid(String bid) {
		this.bid = bid;
	}

	public String getDoorSerial() {
		return doorSerial;
	}

	public void setDoorSerial(String doorSerial) {
		this.doorSerial = doorSerial;
	}

	public String getDoorName() {
		return doorName;
	}

	public void setDoorName(String doorName) {
		this.doorName = doorName;
	}

	public String getDoorAddress() {
		return doorAddress;
	}

	public void setDoorAddress(String doorAddress) {
		this.doorAddress = doorAddress;
	}

	public Integer getDoorSystem() {
		return doorSystem;
	}

	public void setDoorSystem(Integer doorSystem) {
		this.doorSystem = doorSystem;
	}

	public Integer getDoorTic() {
		return doorTic;
	}

	public void setDoorTic(Integer doorTic) {
		this.doorTic = doorTic;
	}

	public Integer getDoorChn() {
		return doorChn;
	}

	public void setDoorChn(Integer doorChn) {
		this.doorChn = doorChn;
	}


}
